﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DevCore.DB;
using DevCore.Entity.System;
using DevCore.Refection;
using DevCore.Service.Db;
using DevCore.Utility;

namespace DevCore.Service.Permission
{
    /// <summary>
    /// 用户服务类
    /// </summary>
    public class UserInfoService
    {
        /// <summary>
        /// 检查用户登录是否成功
        /// </summary>
        /// <param name="userCode">用户编码</param>
        /// <param name="userPassword">用户密码</param>
        /// <param name="orgCode">机构编码</param>
        /// <param name="currentLoginInfo">返回用户登录后相关信息</param>
        /// <returns>1 表示当前的用户名与密码是正确的, -1 表示当前的用户名或者密码不正确</returns>
        public static int CheckUserLogin(String userCode, String userPassword, String orgCode, out UserLoginInfo currentLoginInfo)
        {
            int rValue = -1;
            UserLoginInfo userLoginInfo = new UserLoginInfo();
            List<DbParamInfo> dicParams = new List<DbParamInfo>();
            dicParams.Add(new DbParamInfo() { Name = "UserCode", Direction = 0, Size = 50, Value = userCode, DbType = "VarChar" });
            dicParams.Add(new DbParamInfo() { Name = "UserPassword", Direction = 0, Size = 50, Value = userPassword, DbType = "VarChar" });
            dicParams.Add(new DbParamInfo() { Name = "orgCode", Direction = 0, Size = 50, Value = orgCode, DbType = "VarChar" });
            dicParams.Add(new DbParamInfo() { Name = "status", Direction = 1, Size = 50, Value = 0, DbType = "Int" });
            DataTable dt = DbDataService.ExecuteDataTableProc("App_Sp_sGetUserLoginInfo", dicParams);
            rValue = StringHelper.ObjectToT<int>(DbDataService.GetDbParamValue("status", dicParams),rValue);
            RefectionHelper.SetEntityInfo<UserLoginInfo>(userLoginInfo, dt);
            currentLoginInfo = userLoginInfo;
            return rValue;
        }
    }
}
